package com.demo;

public class Singleton {
    private static Singleton singleton;

    private class A {

    }

    public static Singleton getSingleton() {
        if (singleton == null) {
            System.out.println("拿锁");
            synchronized (Singleton.class) {

                System.out.println("----------------------创建");
                singleton = new Singleton();
            }
            singleton = new Singleton();
        }
        System.out.println("不用创建直接拿");

        return singleton;
    }


}
